package org.algorithm.YaYa.链表;

import org.algorithm.biubiu.wheel_1.common.ListNode;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @Date 2022/2/25
 * @Link {https://leetcode-cn.com/problems/next-greater-node-in-linked-list/}
 */
public class 链表中下一个最大的节点 {


    @Test
    public  void  test(){
        int[] ints = nextLargerNodes(ListNode.build(1, 7, 5, 1, 9, 2, 5, 1));
        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }
    }

    public int[] nextLargerNodes(ListNode head) {
        List<Integer> resultList = new ArrayList<Integer>();
        while (head != null) {
            resultList.add(head.val);
            head = head.next;
        }
        int[] res = new int[resultList.size()];
        for (int i = 0; i < resultList.size() - 1; i++) {
            for (int j = i + 1; j < resultList.size(); j++) {
                if(resultList.get(j)>resultList.get(i)){
                    res[i]=resultList.get(j);
                    break;
                }
            }
        }
        return res;
    }
}
